package com.wanxi.service.product.impl;

import com.wanxi.dao.product.IProductDao;
import com.wanxi.dao.product.impl.ProductDaoImpl;
import com.wanxi.domain.ResultModel;
import com.wanxi.domain.product.ProductModel;
import com.wanxi.service.product.IProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ProductServiceImpl implements IProductService {

    @Autowired
    private IProductDao productDao;

    @Override
    public List<ProductModel> findAll(int page, int limit) {

        int count = productDao.getCount();

        List<ProductModel> productModels = productDao.findAll(page, limit,count);

        return productModels ;
    }

    @Override
    public int deleteByid(int id) {
        int num = productDao.deleteById(id);

      /*  ResultModel resultModel = new ResultModel();
        resultModel.setCount(num);*/

        return num;
    }

    @Override
    public ProductModel findById(int id) {
        ProductModel productModel = productDao.findById(id);

        /*ResultModel resultModel = new ResultModel();
        if (productModel != null) {
            resultModel.setMsg("success");
            resultModel.setData(productModel);
        } else {
            resultModel.setMsg("error");
        }*/
        return productModel;
    }

    //更新产品信息
    @Override
    public int update(ProductModel productModel) {

        int num = productDao.update(productModel);

       /* ResultModel resultModel = new ResultModel();
        if (num > 0) {
            resultModel.setMsg("success");
            return resultModel;
        } else {
            resultModel.setMsg("error");
        }*/

        return num;
    }


    //增加产品信息
    @Override
    public int insert(ProductModel productModel) {
        int num = productDao.insert(productModel);
        /*ResultModel resultModel = new ResultModel();
        if (num > 0) {
            resultModel.setMsg("success");
            resultModel.setData(num);
        } else {
            resultModel.setMsg("error");
        }*/

        return num;
    }

}
